package com.changgou.oauth.config;

import com.changgou.oauth.util.JwtToken;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

/**
 * @Author tang.qingbo
 * @Date 2020/9/5 17:05
 * @Version 1.0
 */
@Configuration
public class FeignOauth2RequestInterceptor implements RequestInterceptor {

    /**
     * 在restTemplate进程远程调用前执行该方法
     * @param requestTemplate
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //生成一个临时令牌
        String jwt = JwtToken.adminJwt();
        //拼接token
        String token = "bearer " + jwt;
        //将零时令牌放入restTemplate请求头中
        requestTemplate.header("Authorization", token);
    }
}
